﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLBV_Nhom8
{
    public partial class frmDangNhap : Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            //txtUserName.Text = "admin";
            //txtPassword.Text = "123";

            if (txtUserName.Text == "")
            {
                MessageBox.Show("Nhập tên đăng nhập.");
                txtUserName.Focus();
                return;
            }

            if (txtPassword.Text == "")
            {
                MessageBox.Show("Nhập password.");
                txtPassword.Focus();
                return;
            }


            DataTable dt = NhanVienBUS.Login(txtUserName.Text, txtPassword.Text);
            if (dt.Rows.Count == 1)
            {                
                NhanVienDTO nhanvien = new NhanVienDTO();
                nhanvien.MaNhanVien= Convert.ToInt32(dt.Rows[0][0]);
                nhanvien.TenNhanVien = dt.Rows[0][1].ToString();
                nhanvien.UserName = dt.Rows[0][2].ToString();
                nhanvien.BoPhan = dt.Rows[0][3].ToString();
                Common.SessionNV = nhanvien;

                Main main = new Main();
                BoPhan = Common.SessionNV.BoPhan;
                UserName = Common.SessionNV.UserName;
                MessageBox.Show("Login Success");
                this.Hide();
                main.ShowDialog();
                this.Close();
            }
            else
                MessageBox.Show("Login Unsuccess");
        }

        public static string BoPhan = "";
        public static string UserName = "";


    }
}